#include "chat.h"

void* share_memory;

int main(){
    key_t key = ftok(".", 20210106);
    int shmid;
    if((shmid = shmget(key, sizeof(struct Msg), IPC_CREAT | 0666)) < 0){
        perror("shmget");
        exit(1);
    }

    if((share_memory = shmat(shmid, NULL, 0)) == (void*)-1){
        perror("shmat");
        exit(1);
    }

    struct Msg* message = (struct Msg*)share_memory;
    memset(message, 0, sizeof(struct Msg));
    char temp[] = "server";
    strcpy(message->name, temp);

    while(1){
        sleep(2);
        if(strlen(message->msg)){
            printf("%s : %s\n", message->name, message->msg);
            memset(message, 0, sizeof(struct Msg));
        }
    }
    return 0;
}